<?php

namespace App\Http\Controllers\Reception;
use App\Tables\trip_content;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use\App\Http\Middleware\CrossHttp;
use Illuminate\Support\Facades\Storage;

class tripContent extends Controller
{
	public function post_pic(Request $request){
      $pan=request()->file('file')->store('images','public');
      $name = request()->file('file') -> getClientOriginalName();
      $url = '/upload/'.$pan;
      $save =[
         'name'=>$name,
          'url'=>$url
      ];
      return $save;}

  public function add_content(Request $request){
    $add = new trip_content;
    $data=$request->all();
    $add_data=$data['form'];
    $add->title=$add_data['title'];
    $add->trip_writer=$add_data['writter'];
    $add->trip_content=$add_data['textarea3'];
           $a=$add_data['imgname'];
           $b=$add_data['imgurl'];
     $str1 = implode($a, ',');
     $str2 = implode($b, ',');
     $pic=[
        'name'=>$str1,
        'url'=>$str2
     ];
     $str=implode($pic, ',');
     $add->pic=$str;
     $add->trip_time=$add_data['value1'];
     $add->save();
     return $str;
  }
  public function view_trip_content(Request $request){
     $view_trip_content= trip_content::all();
     $num = sizeof($view_trip_content);
     for($i=0;$i<$num;$i++){
      $view_trip_content[$i]['trip_time']=substr($view_trip_content[$i]['trip_time'], 0, 10);
      $view_trip_content[$i]['pic']=explode(',',$view_trip_content[$i]['pic']);
      $num1=sizeof($view_trip_content[$i]['pic']);
      $num2=$num1/2;
      $view_trip_content[$i]['pic']=array_slice($view_trip_content[$i]['pic'],$num2,$num2);
     }
     return $view_trip_content;
  }
      public function delete_trip_content($id){
        $delete = trip_content::where('id',$id)->delete();
        return $delete ;
    }

}
